#include"TcpServer3.hpp"
#include"Dict.hpp"

//这是一个用来做测试的回调函数
std::string defaulthandler(const std::string &word, InetAddr &addr)
{
    LOG(LogLevel::DEBUG) << "回调到了defaulthandler";
    std::string s = "haha, ";
    s += word;
    return s;
}

void Usage(std::string proc)
{
    std::cerr << "Usage: " << proc << " port" << std::endl;
}

// ./tcpserver port
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Usage(argv[0]);
        exit(USAGE_ERR);
    }
    uint16_t port = std::stoi(argv[1]);

    Enable_Console_Log_Strategy();

    //std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port,defaulthandler); // 测试


    // 1、翻译模块
    Dict dict;
    dict.LoadDict();

    // 2、网络服务器模块
    std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port,[&dict](const std::string& word, InetAddr &addr){
        return dict.Translate(word,addr);
    });
                                                                  
    tsvr->Init();
    tsvr->Run();

    return 0;
}
